home *** CD-ROM | disk | FTP | other *** search
- /* tell.c --- p 506 */
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- main()
- {
- int fhandle, count;
- long curpos;
- unsigned char buffer[80];
- /* Open the file "autoexec.bat." */
- if ( (fhandle= open("c:\\autoexec.bat", O_RDONLY)) == -1)
- {
- printf("open failed");
- exit(1);
- }
- /* Display current position using "tell" */
- curpos = tell(fhandle);
- printf("Currently at position %ld in 'autoexec.bat'\n", curpos);
- /* Now read 80 bytes and check position again */
- if ((count = read(fhandle, buffer, 80)) == -1)
- {
- perror("read error");
- exit(1);
- }
- printf("Read following 80 characters:\n");
- write(1, buffer, count);
- curpos = tell(fhandle);
- printf("\nNow at position: %ld bytes from beginning\n", curpos);
- }